<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core">

    <body>
        <ui:composition template="/publico/template.xhtml">
            <ui:define name="content">
                <p:messages/>

                <h:form id="fprincipal">
                    <p:panel id="pprincipal" 
                             header="Enriquecimento">
                        <h:panelGrid id="pgprincipal"
                                     columns="2"
                                     cellpadding="8">
                            <h:outputLabel 
                                for="itlote"
                                value="Lote: "/>
                            <p:inputText
                                id="itlote" 
                                value="#{processoBean.processo.id}"
                                readonly="true"/>

                            <h:outputLabel 
                                for="sonutriente"
                                value="Nutriente: "/>
                            <h:selectOneMenu 
                                id="sonutriente" 
                                value="#{processoBean.enriquecimento.nutriente}"
                                converter="NutrienteConversor">
                                <f:selectItems value="#{nutrienteBean.nutrientes}"
                                               var="n"
                                               itemLabel="#{n.nome}"
                                               itemValue="#{n}"/>
                            </h:selectOneMenu>

                            <h:outputLabel 
                                for="itquantidade"
                                value="Quantidade: "/>
                            <p:inputText
                                id="itquantidade" 
                                value="#{processoBean.enriquecimento.quantidade}"/>
                        </h:panelGrid>

                        <p:commandButton 
                            id="cbsalvar" 
                            value="Adicionar"
                            action="#{processoBean.salvarEnriquecimento()}"
                            update="@form, :fenriquecimento"/>

                        <p:button value="Voltar"
                                  outcome="/restrito/lote/informacao-lote.xhtml"/>
                    </p:panel> 
                </h:form>

                <!--                LISTAGEM-->
                <h:form id="fenriquecimento">
                    <p:panel>
                        <p:dataTable
                            value="#{processoBean.enriquecimentos}"
                            var="e"
                            emptyMessage="sem registros">
                            <p:column headerText="Id">
                                <h:outputLabel value="#{e.id}"/>
                            </p:column>

                            <p:column headerText="Nutriente">
                                <h:outputLabel value="#{e.nutriente.nome}"/>
                            </p:column>

                            <p:column headerText="Quantidade">
                                <h:outputLabel value="#{e.quantidade}"/>
                            </p:column>

                            <p:column>
                                <p:commandButton id="cbExcluir"
                                                 action="#{processoBean.removerEnriquecimento()}"
                                                 onclick="return confirm('Você tem certeza?')"
                                                 value="Excluir">
                                    <f:setPropertyActionListener 
                                        target="#{processoBean.enriquecimento}" 
                                        value="#{e}"/>
                                </p:commandButton>
                            </p:column>
                        </p:dataTable>
                    </p:panel>
                </h:form>
            </ui:define>
        </ui:composition>
    </body>
</html>
